<?php
	include("include_header.php");
?>
<html>
<head>
	<title>GradeGrid - Sign Up</title>
	<?php include("header.php"); ?>
	<script type="text/javascript" language="javascript">
		function fillErrorSpace(){	
			document.getElementById("error_space").innerHTML = "<p class='error indentCenter'>Please fill in every field.</p>"
		}
		
		/**
		This function is too dependent on files/signup_form.txt
		*/
		function validate(){
			var password = document.getElementById("password")
			var retyped = document.getElementById("repassword")
			var form = document.getElementById("signup")
			var form_elements = form.elements
			var form_limit = form_elements.length
			
			for(i = 0; i < form_limit; i++){
				if(form_elements[i].value == ""){
					fillErrorSpace()
					try{
						form_elements[i].select()
					} catch(err){
					}
					return;
				}
			}
			
			if(password.value == retyped.value){
				form.submit()
			} else{
				alert("Please retype your password")
				retyped.value = ""
				password.value = ""
				password.select()
			}
		}
	</script>
</head>
<body onLoad="writeCopyright()">
	<div class="main">
		<?php include("boilerplate.php"); ?>
		
		<?php if($_SESSION["logged_in"]): ?>
			<p>You are currently logged in. Please log out first to create a new account.</p>
			<p>Trying to create an account for a student? Student accounts are created when you add a student to one of your classes.</p>
		<?php else: ?>
			<form class="pMirror" id="signup" method="post" action="customize.php">
				<div class="form_section" style="width: 90%;"><h1>Open a New Account</h1></div>
				<p>All fields are required.</p>
				<table style="border: none;" class="pMirror">
					<tr>
						<td class="indentRight">Log-in ID:</td>
						<td><input type="text" name="username" id="loginid" /></td>
					</tr>
					<tr>
						<td class="indentRight">Password:</td>
						<td><input type="password" name="password" id="password" /></td>
					</tr>
					<tr>
						<td class="indentRight">Retype Password:</td>
						<td><input type="password" name="repassword" id="repassword" /></td>
					</tr>
					<tr>
						<td class="indentRight">Email:</td>
						<td><input type="text" name="email" id="email" /></td>
					</tr>
				</table>
				
				<input type="button" onClick="validate()" value="Sign-up" />
		<?php endif ?>
	<div id="error_space"></div>
</form>
	</div>
	<div id="copywright"></div>
</body>
</html>